package com.jt.tenant.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetInsSelect;
import com.jt.tenant.widget.Tools;

import java.util.List;

/**
 * Created by Administrator on 2016/4/7.
 */
public class InsCheckSelectAdapter extends BaseAdapter {

    private Context context;

    private List<GetInsSelect.InsItem> list;

    public InsCheckSelectAdapter(Context context, List<GetInsSelect.InsItem> list) {

        this.context = context;

        this.list = list;


    }


    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {

        return list.get(position);

    }

    @Override
    public long getItemId(int position) {

        return position;

    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            convertView = View.inflate(context, R.layout.item_ins_check_select, null);

            JTApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            holder = new ViewHolder();

            holder.name = (TextView) convertView.findViewById(R.id.tv_ins_check_select_name);

            holder.money = (TextView) convertView.findViewById(R.id.tv_ins_check_item_money);

            holder.price = (TextView) convertView.findViewById(R.id.tv_ins_check_item_price);

            holder.iop_price = (TextView) convertView.findViewById(R.id.tv_ins_check_item_iop);

            holder.iop = (LinearLayout)convertView.findViewById(R.id.lin_ins_check_select_iop);

            holder.divide = (View)convertView.findViewById(R.id.view_ins_check_select);

            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }

        holder.name.setText(list.get(position).name);

        if(Tools.F_num(list.get(position).baoe).equals("0")||Tools.F_num(list.get(position).baoe).equals("")) {

            holder.money.setText("等待查询");

        }else if(Tools.F_num(list.get(position).baoe).equals("1")){

            holder.money.setText("国产");

        }else if(Tools.F_num(list.get(position).baoe).equals("2")){

            holder.money.setText("进口");

        }else {

            holder.money.setText(Tools.F_num(list.get(position).baoe) + "元");

        }

        if(Tools.F_num((list.get(position).price)).equals("1")||Tools.F_num((list.get(position).price)).equals("0")){

            holder.price.setText("待查询");

        }else {

            holder.price.setText(list.get(position).price+"元");

        }

        if(list.get(position).flag.equals("1")){

            holder.iop_price.setText("待查询");

        }else {

            holder.iop_price.setText(list.get(position).flag + "元");

        }

        if(!list.get(position).flag.equals("0")) {

            holder.divide.setVisibility(View.VISIBLE);

            holder.iop.setVisibility(View.VISIBLE);

        }

        return convertView;

    }

    class ViewHolder {

        private TextView name;

        private TextView money;

        private TextView price;

        private TextView iop_price;

        private LinearLayout iop;

        private View divide;


    }

}
